--[[
* 能量变更后
*]]
---@class BuffEffect69 : BaseBuffEffect
BuffEffect69 = ClientFight.CreateClass("BuffEffect69", ClientFight.BaseBuffEffect)
local t = BuffEffect69
---@param fight Fight
---@param buff FighterBuff
local BUFF_EFFECT_69_COUNT_COST_HP = "BUFF_EFFECT_69_COUNT_COST_HP_";
function t:action(fight, buff, ...)
    ---fighter, skillId, energy,reason
    local target = buff.target;
    if (parameters.length < 3) then
    return IBuffEffect.FAIL;
    end

    local result = parameters[3];
    if (not result:isDamage()) then
    return IBuffEffect.FAIL;
    end
    if (not AttackUtils.isDamage(resultstate))then
    return IBuffEffect.FAIL;
    end
    local buffEffectValue = buff.buffBeanf_BuffEffectValue;
    local oldVlaue = buffattributesattributes[buffEffectValue[2]]or 0;
    if (oldVlaue >= buffEffectValue[4]) then
        SkillRoleMgr.savePathFile( "[" .. fightframe .. "][EFFECT]Fighter " .. buff.targetfighterId .. " Buff"
    .. buffmodelId .. " 触发每累积损失生命, 获得属性 "..buffEffectValue[2].." 达到上限: " .. oldVlaue);
    return IBuffEffect.FAIL;
    end
    local maxHp = FighterAttributeManager.getFightAttr(target, FighterAttributeEnum.HP);
    local damage = resultdamage;
    local currPer = (damage / maxHp * Global.TEN_THOUSANDTH);

    --已累积损失生命
    local costHpPer =  buffeffectParams[BUFF_EFFECT_69_COUNT_COST_HP] or 0;
    costHpPer = costHpPer + currPer;
    buff.effectParams[BUFF_EFFECT_69_COUNT_COST_HP] = costHpPer;--累计减血%% 存储下来

    local step = costHpPer / buffEffectValue[1];
    local totalValue = step * buffEffectValue[3]; --计算应该增加的属性值
    if (totalValue <= oldVlaue) then
    return IBuffEffect.FAIL;
    end
    if (totalValue >= buffEffectValue[4]) then
    totalValue = buffEffectValue[4];
    end
    buffattributes.attributes[buffEffectValue[2]] = totalValue; --计算应该增加的属性值

    local logCostHpPer = costHpPer;
    local logTotalValue = totalValue;
    SkillRoleMgr.savePathFile("[" .. fightframe .. "][EFFECT]Fighter " .. buff.targetfighterId .. " Buff"
    .. buffmodelId .. " 触发每累积损失生命"..buffEffectValue[1].." %% 增加 " .. buffEffectValue[2] .. "属性 "..buffEffectValue[3].." 点, 当前总增加属性值: " .. logTotalValue .." , 本次损失生命:"..currPer .."%% 总累计损失生命:"..logCostHpPer .."%%");
     ClientFight.BaseBuffEffect.action(self, fight, buff, parameters);
    return IBuffEffect.SUCCESS_ATTRI_HAS_CHANGE;
end

t.New()